{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Stefan-Boltzmann Law"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<i>© Von P. Walden, Washington State University</i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pylab inline\n",
    "from bt2rad_wv import bt2rad_wv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "wv = np.arange(0.1, 100000, 0.05)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Calculate the Planck Functions for the Earth and Sun"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Learth = bt2rad_wv(wv,288.)\n",
    "Lsun   = bt2rad_wv(wv,5800.)\n",
    "\n",
    "figure(figsize=(16,8))\n",
    "loglog(wv,Learth,'b',wv,Lsun,'r')\n",
    "axis([0.1, 100000, 10e-11, 10e9]);\n",
    "xlabel('WAVELENGTH (um)')\n",
    "ylabel('PLANCK RADIANCE (W m-2 sr-1 um-1)')\n",
    "title('Planck Functions at Temperatures of Sun and Earth')\n",
    "legend(['Earth', 'Sun'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Now integrate the area under the curves, which yields the spectrally-integrated radiance in W m-2 sr-1:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "L_BB_Earth = trapz(Learth,wv)\n",
    "L_BB_Sun   = trapz(Lsun,wv)\n",
    "print('The spectrally-integrated radiances for the Earth is ', L_BB_Earth, 'W m-2 sr-1')\n",
    "print('The spectrally-integrated radiances for the Sun is   ', L_BB_Sun, 'W m-2 sr-1')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### But this is not quite what we want!!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### We would rather have the total radiant exitance, or Flux in W m-2."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### How do we calculate the flux?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "M_BB_Earth = trapz(Learth,wv) * pi\n",
    "M_BB_Sun   = trapz(Lsun,wv) * pi\n",
    "print('The spectrally-integrated radiances for the Earth is ', M_BB_Earth, 'W m-2')\n",
    "print('The spectrally-integrated radiances for the Earth is ', M_BB_Sun, 'W m-2')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
